public class race implements Runnable {
    private static String winner;

    @Override
    public void run() {

        for (int i = 0; i <= 1000; i++) {
            if (Thread.currentThread().getName().equals("兔子")&&i%10==0)
            {
                try {
                    Thread.sleep(5);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if (gameover(i)) {
                break;
            }
        }
    }

    public boolean gameover(int i) {
        if (winner != null) {
            return true;
        } else if (i < 1000) {
            System.out.println(Thread.currentThread().getName() + "跑了" + i + "步了");
            return false;
        } else {
            System.out.println("胜利者是" + Thread.currentThread().getName());
            winner = Thread.currentThread().getName();
            return true;
        }
    }

    public static void main(String[] args) {
        new Thread(new race(), "乌龟").start();
        new Thread(new race(), "兔子").start();
    }
}
//这里是一个经典的龟兔赛跑问题，使用了两个线程，分别命名为兔子和乌龟
// run方法中进行一次1到1000的计数循环。让兔子每跑10步休息5毫秒。当一个线程循环结束时结束进程
